<?php

namespace Lettral\LetterBundle\Controller;

use Lettral\Helpers;

use Symfony\Bundle\FrameworkBundle\Controller\Controller;
use Symfony\Component\Security\Core\Exception\AccessDeniedException;
use Symfony\Component\HttpFoundation\Request;
use Symfony\Component\HttpKernel\Exception\NotFoundHttpException;
use \Symfony\Component\HttpFoundation\Response;

class CpVilleController extends Controller
{
    public function listAction($cp)
    {
    	$em = $this->container->get('doctrine')->getEntityManager();    	
    	$query = $em->createQuery("SELECT cp.commune FROM LettralLetterBundle:CpVille cp WHERE cp.cp LIKE :p1");
    	$query->setParameter('p1', $cp);
    	$lCp = $query->getResult();
    	
    	$response = new \Symfony\Component\HttpFoundation\Response();
    	
    	$response->headers->set('Content-Type', 'application/json; charset=UTF-8');
    	$response->setContent(json_encode($lCp));
    	
    	return $response;
    }
    
}
